 package uk.co.mmscomputing.util;
 
 import java.awt.Component;
 import java.awt.Graphics;
 import java.awt.Rectangle;
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
 import javax.swing.Icon;
 import javax.swing.JFrame;
 import javax.swing.JOptionPane;
 import javax.swing.JTabbedPane;
 
 public class UtilTabCloseIcon
   implements Icon
 {
   private final Icon mIcon;
   private JTabbedPane mTabbedPane = null;
   private transient Rectangle mPosition = null;
   private boolean closed;
 
   public UtilTabCloseIcon(Icon paramIcon)
   {
     this.mIcon = paramIcon;
   }
 
   public UtilTabCloseIcon()
   {
     this.mIcon = new JarImageIcon(getClass(), "16x16/delete.png");
   }
 
   public void paintIcon(Component paramComponent, Graphics paramGraphics, int paramInt1, int paramInt2)
   {
     if (null == this.mTabbedPane)
     {
       this.mTabbedPane = ((JTabbedPane)paramComponent);
       this.mTabbedPane.addMouseListener(new MouseAdapter()
       {
         public void mouseReleased(MouseEvent paramAnonymousMouseEvent)
         {
           if ((!paramAnonymousMouseEvent.isConsumed()) && (UtilTabCloseIcon.this.mPosition.contains(paramAnonymousMouseEvent.getX(), paramAnonymousMouseEvent.getY())))
           {
             if (!UtilTabCloseIcon.this.closed) {
               if (JOptionPane.showConfirmDialog(new JFrame(), "Do you really want to discard this image ?", "Close", 0) == 0)
               {
                 UtilTabCloseIcon.this.closed = true;
                 int i = UtilTabCloseIcon.this.mTabbedPane.getSelectedIndex();
                 UtilTabCloseIcon.this.mTabbedPane.remove(i);
                 paramAnonymousMouseEvent.consume();
               } else {
                 UtilTabCloseIcon.this.closed = false;
               }
             }
           }
         }
       });
     }
     this.mPosition = new Rectangle(paramInt1, paramInt2, getIconWidth(), getIconHeight());
     this.mIcon.paintIcon(paramComponent, paramGraphics, paramInt1, paramInt2);
   }
 
   public int getIconWidth()
   {
     return this.mIcon.getIconWidth();
   }
 
   public int getIconHeight()
   {
     return this.mIcon.getIconHeight();
   }
 }

